package com.qls.mt.biz.data.controller;

import com.qls.core.dto.InitBody;
import com.qls.core.dto.PushHotelBody;
import com.qls.core.entity.DtOrderChannels;
import com.qls.core.utils.R;
import com.qls.mt.biz.common.service.DtOrderChannelsService;
import com.qls.mt.biz.data.service.InsertHtService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("hotel")
@EnableAsync
@Slf4j
public class MtDataController {

    @Autowired
    private InsertHtService insertHtService;

    @Autowired
    private DtOrderChannelsService dtOrderChannelsService;

    @PostMapping(value = "detail")
    public R hotelDetail(@RequestBody InitBody initBody) {
        PushHotelBody pushHotelBody = new PushHotelBody();
        pushHotelBody.setHotelId(initBody.getHotelId());
        Map<String, Object> map = new HashMap<>();
        map.put("partnerId", initBody.getPartnerId());
        map.put("accessKey", initBody.getAccessKey());
        map.put("secretKey", initBody.getSecretKey());
        //放入数据库
        insertHtService.insertHtHotelinfo(pushHotelBody, map);
        return R.ok();
    }

    @PostMapping(value = "hotel_all")
    public R hotelAll(@RequestBody PushHotelBody pushHotelBody) {
        //放入数据库
        Map<String, Object> map = new HashMap<>();
        DtOrderChannels dtOrderChannels = dtOrderChannelsService.queryByHotelId(pushHotelBody.getHotelId());
        map.put("partnerId", dtOrderChannels.getPartnerId());
        map.put("accessKey", dtOrderChannels.getAccessKey());
        map.put("secretKey", dtOrderChannels.getSecret());
        insertHtService.insertHtHotelinfo(pushHotelBody, map);
        List<Long> listRoom = insertHtService.insertHtPhyicalRoom(pushHotelBody, map);
        List<Long> listRp = insertHtService.insertLogicRoom(pushHotelBody, listRoom, map);
        insertHtService.rates(pushHotelBody, listRp, map);
        return R.ok();
    }

    @GetMapping(value = "pull_all")
    public R pullAll(@RequestParam Map<String, Object> params) {
        //拉取酒店Id列表
        Integer dtId = Integer.valueOf(params.get("dtId").toString());
        insertHtService.repeat(dtId);
        return R.ok();
    }
}
